package com.alkaid.commons.core;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Kylin
 * 缓存key配置
 */
public class CacheKeyDefinition {
    /**
     * 默认缓存时间 30天
     */
    public static long CACHE_TIME_DEFAULT = 60 * 60 * 24 * 30;
    /**
     * 默认缓存时间 7天
     */
    public static long CACHE_TIME_WEEK = 60 * 60 * 24 * 7;
    /**
     * 缓存时间 1天
     */
    public static long CACHE_TIME_DAY = 60 * 60 * 24;
    /**
     * 验证码缓存key
     */
    public static final Map<String, String> SMS_KEY_MAP = new HashMap<>();
    /**
     * 等级表缓存key
     */
    public static final String LEV_LIST_KEY = "LEV_LIST";

    /**
     * 评论key
     *
     * @param animeId 番剧ID
     * @return the Comment key
     */
    public static String getCommentKey(Integer animeId) {
        return "COMMENTS_" + animeId;
    }

    /**
     * 投币key
     *
     * @param userId  用户ID
     * @param animeId 番剧ID
     * @return the thumb key
     */
    public static String getCoinsKey(Long userId, Integer animeId) {
        return "COINS_" + userId + "_" + animeId;
    }

    /**
     * 点赞key
     *
     * @param userId  用户ID
     * @param animeId 番剧ID
     * @return the thumb key
     */
    public static String getThumbKey(Long userId, Integer animeId) {
        return "THUMB_" + userId + "_" + animeId;
    }

    /**
     * 追番key
     *
     * @param userId  用户ID
     * @param animeId 番剧ID
     * @return the collect key
     */
    public static String getCollectKey(Long userId, Integer animeId) {
        return "COLLECT_" + userId + "_" + animeId;
    }

    /**
     * 追番列表key
     *
     * @param userId 用户ID
     * @return the collect key
     */
    public static String getCollectListKey(Long userId) {
        return "COLLECT_LIST_" + userId;
    }

    /**
     * anime历史观看key.
     *
     * @param userId  the user id
     * @param animeId the anime id
     * @return the anime history key
     */
    public static String getAnimeHistoryKey(Long userId, Integer animeId) {
        return "ANIME_HISTORY_" + userId + "_" + animeId;
    }

    /**
     * anime video历史观看key.
     *
     * @param userId       the user id
     * @param animeVideoId the anime video id
     * @return the anime video history key
     */
    public static String getAnimeVideoHistoryKey(Long userId, Long animeVideoId) {
        return "ANIME_VIDEO_HISTORY_" + userId + "_" + animeVideoId;
    }

    /**
     * 轮播图key
     *
     * @param page the page
     * @return the indicator key
     */
    public static String getIndicatorKey(int page) {
        String date = new SimpleDateFormat("yyyy_MM_dd").format(new Date());
        return "INDICATORS_" + page + "_" + date;
    }

    static {
        SMS_KEY_MAP.put("reg", "SMS_REG_");
        SMS_KEY_MAP.put("login", "SMS_LOGIN_");
        SMS_KEY_MAP.put("forget", "SMS_FORGET_");
    }
}
